home *** CD-ROM | disk | FTP | other *** search
/ ADA Programming Guide / ADA Programming Guide.iso / ada_gnu / adainc / s-widwch.adb < prev    next >
Text File  |  1996-01-30  |  3KB  |  75 lines

  1. ------------------------------------------------------------------------------
  2. --                                                                          --
  3. --                         GNAT RUNTIME COMPONENTS                          --
  4. --                                                                          --
  5. --                     S Y S T E M . W I D _ W C H A R                      --
  6. --                                                                          --
  7. --                                 B o d y                                  --
  8. --                                                                          --
  9. --                            $Revision: 1.4 $                              --
  10. --                                                                          --
  11. --           Copyright (c) 1992,1993,1994 NYU, All Rights Reserved          --
  12. --                                                                          --
  13. -- The GNAT library is free software; you can redistribute it and/or modify --
  14. -- it under terms of the GNU Library General Public License as published by --
  15. -- the Free Software  Foundation; either version 2, or (at your option) any --
  16. -- later version.  The GNAT library is distributed in the hope that it will --
  17. -- be useful, but WITHOUT ANY WARRANTY;  without even  the implied warranty --
  18. -- of MERCHANTABILITY  or  FITNESS FOR  A PARTICULAR PURPOSE.  See the  GNU --
  19. -- Library  General  Public  License for  more  details.  You  should  have --
  20. -- received  a copy of the GNU  Library  General Public License  along with --
  21. -- the GNAT library;  see the file  COPYING.LIB.  If not, write to the Free --
  22. -- Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.        --
  23. --                                                                          --
  24. ------------------------------------------------------------------------------
  25.  
  26. with System.WCh_Con; use System.WCh_Con;
  27.  
  28. package body System.Wid_WChar is
  29.  
  30.    --------------------------
  31.    -- Width_Wide_Character --
  32.    --------------------------
  33.  
  34.    function Width_Wide_Character
  35.      (Lo, Hi : Wide_Character;
  36.       EM     : WC_Encoding_Method)
  37.       return   Natural
  38.    is
  39.       W : Natural;
  40.       P : Natural;
  41.  
  42.    begin
  43.       W := 0;
  44.  
  45.       for C in Lo .. Hi loop
  46.          P := Wide_Character'Pos (C);
  47.  
  48.          --  If we are in wide character range, just use width of encoding
  49.          --  sequence (currently a constant for all encoding methods) and
  50.          --  we are done.
  51.  
  52.          if P > 255 then
  53.             if EM = WCEM_Hex then
  54.                return Natural'Max (W, 5);
  55.             else
  56.                return Natural'Max (W, 2);
  57.             end if;
  58.  
  59.          --  If we are in character range then use length of character image
  60.  
  61.          else
  62.             declare
  63.                S : String := Character'Image (Character'Val (P));
  64.  
  65.             begin
  66.                W := Natural'Max (W, S'Length);
  67.             end;
  68.          end if;
  69.       end loop;
  70.  
  71.       return W;
  72.    end Width_Wide_Character;
  73.  
  74. end System.Wid_WChar;
  75.